package com.jl.jlapp.mvp.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.AddressListAdapter;
import com.jl.jlapp.eneity.ShipAddressModel;
import com.jl.jlapp.eneity.ShipAddressModel.ResultDataBean;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.List;

public class ChooseAddressActivity
        extends AppCompatActivity {
    public static OnClicktem onClicktem;
    @BindView(R.id.rlv_address_list)
    RecyclerView rlvAddressList;
    List<ShipAddressModel.ResultDataBean> shipAddressResultDataBeans;
    int userId = 0;
    int whichPage = 0;

    private void initView() {
        Object localObject = new LinearLayoutManager(this);
        this.rlvAddressList.setLayoutManager((LayoutManager) localObject);
        localObject = new AddressListAdapter(R.layout.item_choose_address, this.shipAddressResultDataBeans);
        this.rlvAddressList.setAdapter((Adapter) localObject);
        ((AddressListAdapter) localObject).setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                TextView tvName = (TextView) paramAnonymousView.findViewById(R.id.tv_person_name);
                TextView localTextView1 = (TextView) paramAnonymousView.findViewById(R.id.tv_person_phone);
                TextView localTextView2 = (TextView) paramAnonymousView.findViewById(R.id.tv_address_details);
                paramAnonymousView = (TextView) paramAnonymousView.findViewById(R.id.tv_default);
                Intent localIntent = new Intent();
                localIntent.putExtra("name", tvName.getText().toString().trim());
                localIntent.putExtra("phone", localTextView1.getText().toString().trim());
                localIntent.putExtra("address", localTextView2.getText().toString().trim());
                localIntent.putExtra("provinceCode", ((ShipAddressModel.ResultDataBean) ChooseAddressActivity.this.shipAddressResultDataBeans.get(paramAnonymousInt)).getProvinceCode());
                localIntent.putExtra("cityCode", ((ShipAddressModel.ResultDataBean) ChooseAddressActivity.this.shipAddressResultDataBeans.get(paramAnonymousInt)).getCityCode());
                localIntent.putExtra("countyCode", ((ShipAddressModel.ResultDataBean) ChooseAddressActivity.this.shipAddressResultDataBeans.get(paramAnonymousInt)).getCountyCode());
                localIntent.putExtra("ringCode", ((ShipAddressModel.ResultDataBean) ChooseAddressActivity.this.shipAddressResultDataBeans.get(paramAnonymousInt)).getRingCode());
                if (paramAnonymousView.getVisibility() == View.VISIBLE) {
                    localIntent.putExtra("isDefault", 1);
                    if (ChooseAddressActivity.this.whichPage != 1) {
                    }
                    if (ChooseAddressActivity.onClicktem != null) {
                        ChooseAddressActivity.onClicktem.onClicktem(localTextView2.getText().toString().trim());
                    }
                } else {
                    localIntent.putExtra("isDefault", 0);
                    ChooseAddressActivity.this.setResult(1, localIntent);
                    ChooseAddressActivity.this.finish();

                }
            }
        });
    }

    public static void setOnClicktem(OnClicktem paramOnClicktem) {
        onClicktem = paramOnClicktem;
    }

    public void getShippingAddressByUserId() {
        Net.get().getShippingAddressByUserId(this.userId).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CommonObserver<ShipAddressModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(ShipAddressModel shipAddressModel) {

                    }
                });
    }

    @OnClick({R.id.return_btn, R.id.shipping_address_management})
    public void onClick(View paramView) {
        switch (paramView.getId()) {

            case R.id.return_btn:
                finish();
                break;
            default:
                startActivity(new Intent(this, MyAddressActivity.class));
                break;
        }
    }

    protected void onCreate(@Nullable Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_choose_address);
        ButterKnife.bind(this);
        this.whichPage = getIntent().getIntExtra("whichPage", 0);
        if (this.whichPage == 0) {
            Toast.makeText(this, "数据接收错误", Toast.LENGTH_SHORT).show();
        }
    }

    protected void onResume() {
        super.onResume();
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        if (this.userId > 0) {
            getShippingAddressByUserId();
            return;
        }
        Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, LoginActivity.class));
    }

    public static abstract interface OnClicktem {
        public abstract void onClicktem(String paramString);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/ChooseAddressActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */